package psn.kiko.pojo.vo.ui;

import lombok.Data;
import psn.kiko.constant.DBConstant;

import java.util.List;

/**
 * 操作UI
 */
@Data
public class OperationUI{
	/**
	 * 操作id
	 */
	private Integer id;
	/**
	 * 操作标识
	 */
	private String label;
	/**
	 * 操作标题
	 */
	private String title;
	/**
	 * 操作图标类名
	 */
	private String iconClass;
	/**
	 * <p style="color:blue;font-size:16px;">操作最终是否可用：由操作及对应的接口状态共同决定</p>
	 */
	private Boolean finalStatus;
	
	/**
	 * 操作状态
	 */
	private Short operationStatus;
	private List<InterfaceUI> children;
	
	/**
	 * <h2 style="color:red;">查询完每条记录后，一定调用此方法计算操作的最终可用状态</h2>
	 * 当前操作启用，关联的接口数量大于0，且都处于可用状态
	 */
	public void computeFinalStatus(){
		boolean associatedApiIsAllEnable = this.children.stream().allMatch(api->api.getStatus() == DBConstant.EDITABLE);
		this.finalStatus = (this.operationStatus != null)
				&&(this.operationStatus == DBConstant.ENABLE)
				&&this.children != null
				&&this.children.size() > 0
				&&associatedApiIsAllEnable;
	}
}
